home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5170 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.7 KB  |  40 lines

  1. Path: news.th-darmstadt.de!news!enno
  2. From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: inherited classes / functions
  5. Date: 02 Feb 1996 19:35:38 GMT
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Distribution: world
  8. Message-ID: <ENNO.96Feb2203538@kitz.inferenzsysteme.informatik.th-darmstadt.de>
  9. References: <Pine.A32.3.91.960202182844.45749A-100000@asterix.uni-muenster.de>
  10. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  11. In-reply-to: Gerhard Kutzelnigg's message of Fri, 2 Feb 1996 18:34:43 +0100
  12.  
  13. In article <Pine.A32.3.91.960202182844.45749A-100000@asterix.uni-muenster.de> Gerhard Kutzelnigg <kutzeln@uni-muenster.de> writes:
  14.  
  15.    Hi All,
  16.  
  17.    when using inherited virtual functions, how can I simply call the
  18.    "inherited" function without knowing the name of the parent class? 
  19.  
  20.    -> While I am developing a graphical user interface, I sometimes need to 
  21.    "insert" a class in the class hierarchy, so I don't want to change all the 
  22.    "subclasses" code when "inserting" the new class. In Turbo Pascal there was
  23.    the keyword "inherited" so I could call something like 
  24.    "inherited myfunction ();" but how can I resolve this expression in c++ ???
  25.  
  26. This feature isn't supported in C++. However one can reduce the necessary
  27. modifications by declaring the super-class as a local type 'Super':
  28.  
  29.         class Base { ... f(); ... };
  30.         class Der : public Base { // (1)
  31.            typedef Base Super;    // (2)
  32.            public
  33.             void f1() { ... Super :: f(); ... }
  34.             void f2() { ... Super :: f(); ... }
  35.         };
  36.  
  37. When you insert a new class only (1)+(2) have to be changed.
  38.  
  39.         Enno
  40.